package com.niit.user.web;

import cn.hutool.core.util.IdUtil;
import com.niit.user.pojo.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author yaojianfeng
 */
@RestController
@RequestMapping("/provider/feign")
public class FeignProviderController {
    @Value("${server.port}")
    String serverPort;

    /**
     * request参数的请求
     * @param name
     * @return
     */
    @GetMapping(value = "/request")
    public String requestParam (@RequestParam("name") String name) {
        return "Hello, " + name;
    }

    /**
     * header信息的请求
     * @param name
     * @param address
     * @return
     */
    @GetMapping(value = "/header" )
    public User headerInfo(@RequestHeader String name,
                           @RequestHeader String address) {
        User user = new User();
        user.setId(IdUtil.simpleUUID());
        user.setUsername(name);
        user.setAddress(address);
        user.setServerPort(serverPort);
        return user;
    }

    /**
     * requestbody的请求
     * @param user
     * @return
     */
    @PostMapping(value = "/body")
    public String bodyInfo(@RequestBody User user) {
        return "Hello, " + user.getUsername() + ", " + user.getAddress();
    }
}
